package com.iona.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iona.domain.BaseEntity;
import com.iona.domain.TemplatesForPurview;
import com.iona.json.JSONException;
import com.iona.utils.CreatorUtil;
import com.iona.utils.Storage;

/**
 * Servlet implementation class AddTemplatesForPurviewServlet
 */
@WebServlet("/addtemplatesforpurview")
public class AddTemplatesForPurviewServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	@Override
	public void init() throws ServletException {
		super.init();
		setTransactional(true);
	}
	public void doExecute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			JSONException {
		String typeOfPurview = request.getParameter("typeOfPurview");
		String name = request.getParameter("name");
		String preparationDirection = request.getParameter("preparationDirection");
		String preparationProfile = request.getParameter("preparationProfile");
		String qualification = request.getParameter("qualification");
		String time = request.getParameter("time");
		String importanceOfPurview = request.getParameter("importanceOfPurview");
		String theoreticalDificulty = request.getParameter("theoreticalDificulty");
		String practicalDificulty = request.getParameter("practicalDificulty");
		String baseStructure = request.getParameter("baseStructure");
		String conditionsOfFormation = request.getParameter("conditionsOfFormation");
		String statement = request.getParameter("statement");
		String year = request.getParameter("year");
		String numberOfProtocol = request.getParameter("numberOfProtocol");
		TemplatesForPurview tfp = CreatorUtil.createTemplatesForPurview(typeOfPurview, name,
				preparationDirection, preparationProfile, qualification, time, importanceOfPurview,
				theoreticalDificulty, practicalDificulty, baseStructure, conditionsOfFormation,
				statement, year, numberOfProtocol);
		List<BaseEntity> toCreate = new ArrayList<BaseEntity>();
		toCreate.add(tfp);
		new Storage().storeAll(toCreate, null, null);
		// TODO: add ajax response
		// goToList(request, response);
	}
	}

